package com.sqlcheck.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 大模型优化结果响应
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "大模型优化结果")
public class LLMOptimizationResult {

    @Schema(description = "优化记录ID")
    private Long optimizationId;

    @Schema(description = "原始SQL", required = true)
    private String originalSql;

    @Schema(description = "优化后的SQL", required = true)
    private String optimizedSql;

    @Schema(description = "优化说明")
    private String explanation;

    @Schema(description = "详细的优化说明表格")
    private String optimizationDetails;

    @Schema(description = "高亮变更列表")
    private List<OptimizationHighlight> highlights;

    @Schema(description = "兼容性问题列表")
    private List<CompatibilityIssue> issues;

    @Schema(description = "优化元数据")
    private OptimizationMetadata metadata;

    /**
     * 优化高亮信息
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "优化高亮信息")
    public static class OptimizationHighlight {

        @Schema(description = "变更类型", allowableValues = {"addition", "deletion", "modification"})
        private String type;

        @Schema(description = "行号")
        private Integer line;

        @Schema(description = "列号")
        private Integer column;

        @Schema(description = "长度")
        private Integer length;

        @Schema(description = "变更描述")
        private String description;

        @Schema(description = "原始文本")
        private String originalText;

        @Schema(description = "新文本")
        private String newText;
    }

    /**
     * 兼容性问题
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "兼容性问题")
    public static class CompatibilityIssue {

        @Schema(description = "问题类型")
        private String type;

        @Schema(description = "严重级别", allowableValues = {"HIGH", "MEDIUM", "LOW"})
        private String severity;

        @Schema(description = "问题描述")
        private String description;

        @Schema(description = "修复建议")
        private String suggestion;

        @Schema(description = "行号")
        private Integer line;

        @Schema(description = "列号")
        private Integer column;

        @Schema(description = "相关规则ID")
        private String ruleId;

        @Schema(description = "相关规则名称")
        private String ruleName;
    }

    /**
     * 优化元数据
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "优化元数据")
    public static class OptimizationMetadata {

        @Schema(description = "提供商")
        private String provider;

        @Schema(description = "模型名称")
        private String modelName;

        @Schema(description = "模型版本")
        private String modelVersion;

        @Schema(description = "使用的Token数量")
        private Integer tokensUsed;

        @Schema(description = "处理时间(毫秒)")
        private Long processingTime;

        @Schema(description = "优化时间戳")
        private LocalDateTime timestamp;

        @Schema(description = "使用的提示词模板")
        private String promptTemplate;

        @Schema(description = "请求ID")
        private String requestId;

        @Schema(description = "成本估算")
        private Double estimatedCost;

        @Schema(description = "置信度", example = "0.85")
        private Double confidence;
    }
}